#coding:utf-8
import sys
sys.path.append('..')
import libs.util.http_request_ssl as httpReq
import libs.util.json_enable_chinese as myencode
import get_access_token

def __post_mes(data):
    access_token = get_access_token.get_access_token()
    url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+access_token
    data_json = myencode.json_aesop.encode(data)
    return httpReq(url).do_post_json(data_json)


#1、作业提醒 dic示例
class zytx_class:
    def __init__(self):
        self.first = ''
        self.name = ''
        self.subject = ''
        self.content = ''
        self.remark = ''

#1、作业提醒
def zytx(touser,  url,  data_obj):
    data = {
           "touser":touser,
           "template_id":"1s0R2v1r9l8eMsLP2ZALftr74ZVuAHtsuE2GDhHvz80",
           "url":url,
           "topcolor":"#FF0000",
           "data":{
                   "first": {
                       "value":data_obj.first,
                       "color":"#173177"
                   },
                   "name":{
                       "value":data_obj.name,
                       "color":"#173177"
                   },
                   "subject":{
                       "value":data_obj.subject,
                       "color":"#173177"
                   },
                   "content":{
                       "value":data_obj.content,
                       "color":"#173177"
                   },
                   "remark":{
                       "value":data_obj.remark,
                       "color":"#173177"
                   }
           }
    }
    return __post_mes(data)


#2、考试成绩通知 dic示例
class kscj_class:
    def __init__(self):
        self.first = ''
        self.childName = ''
        self.courseName = ''
        self.time = ''
        self.score = ''
        self.remark = ''

#2、考试成绩通知
def kscj(  touser,  url,  data_obj):
    data = {
           "touser":touser,
           "template_id":"EBi7Hs5bUkY--i_U1SWhPSlbJBRUbH_2ZfkjUtxM9iE",
           "url":url,
           "topcolor":"#FF0000",
           "data":{
                   "first": {
                       "value":data_obj.first,
                       "color":"#173177"
                   },
                   "childName":{
                       "value":data_obj.childName,
                       "color":"#173177"
                   },
                   "courseName":{
                       "value":data_obj.courseName,
                       "color":"#173177"
                   },
                   "time":{
                       "value":data_obj.time,
                       "color":"#173177"
                   },
                   "score":{
                       "value":data_obj.score,
                       "color":"#173177"
                   },
                   "remark":{
                       "value":data_obj.remark,
                       "color":"#173177"
                   }
           }
    }
    return __post_mes(data)

#3、订阅成功通知 dic示例
class dycg_class:
    def __init__(self):
        self.first = ''
        self.keyword1 = ''
        self.keyword2 = ''
        self.remark = ''

#3、订阅成功通知
def dycg( touser, url,  data_obj):
    data = {
           "touser":touser,
           "template_id":"m_8VyoL7UKQzrKBXoXnOL4TdmErmJlKh7RuGZr8mCCU",
           "url":url,
           "topcolor":"#FF0000",
           "data":{
                   "first": {
                       "value":data_obj.first,
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":data_obj.keyword1,
                       "color":"#173177"
                   },
                   "keyword2":{
                       "value":data_obj.keyword2,
                       "color":"#173177"
                   },
                   "remark":{
                       "value":data_obj.remark,
                       "color":"#173177"
                   }
           }
    }
    result =  __post_mes(data)
    print result
    return result

#4、放假通知 dic示例
class fjtz_class:
    def __init__(self):
        self.first = ''
        self.noticeSender = ''
        self.time = ''
        self.status = ''
        self.reason = ''
        self.remark = ''

#4、放假通知
def fjtz(  touser,  url,  data_obj):
    data = {
           "touser":touser,
           "template_id":"n8yHXxRR6F8uTgVk2uu9eXOrV5fXyxbBvDPkI6Ujj2Q",
           "url":url,
           "topcolor":"#FF0000",
           "data":{
                   "first": {
                       "value":data_obj.first,
                       "color":"#173177"
                   },
                   "noticeSender":{
                       "value":data_obj.noticeSender,
                       "color":"#173177"
                   },
                   "time":{
                       "value":data_obj.time,
                       "color":"#173177"
                   },
                   "status":{
                       "value":data_obj.status,
                       "color":"#173177"
                   },
                   "reason":{
                       "value":data_obj.reason,
                       "color":"#173177"
                   },
                   "remark":{
                       "value":data_obj.remark,
                       "color":"#173177"
                   }
           }
    }
    return __post_mes(data)

#5、考试考场安排通知 dic示例
class kskc_class:
    def __init__(self):
        self.first = ''
        self.keyword1 = ''
        self.keyword2 = ''
        self.keyword3 = ''
        self.remark = ''

#5、考试考场安排通知
def kskc(  touser,  url,  data_obj):
    data = {
           "touser":touser,
           "template_id":"xNZIs1GQXOC50k8c37M4Zb_z8bsueFe4UipHbG15s1o",
           "url":url,
           "topcolor":"#FF0000",
           "data":{
                   "first": {
                       "value":data_obj.first,
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":data_obj.keyword1,
                       "color":"#173177"
                   },
                   "keyword2":{
                       "value":data_obj.keyword2,
                       "color":"#173177"
                   },
                   "keyword3":{
                       "value":data_obj.keyword3,
                       "color":"#173177"
                   },
                   "remark":{
                       "value":data_obj.remark,
                       "color":"#173177"
                   }
           }
    }
    return __post_mes(data)


# dic = {
#     "kskc":kskc,
#     "kskc_class":kskc_class,
#     "fjtz":fjtz,
#     "fjtz_class":fjtz_class,
#     "kscj":kscj,
#     "kscj_class":kscj_class,
#     "dycg":dycg,
#     "dycg_class":dycg_class,
#     "zytx":zytx,
#     "zytx_class":zytx_class,
# }
    # print url
    # print data
    # print http_req
if __name__ == '__main__':
    import time
    time.sleep(10)
    data_obj = dycg_class()
    data_obj.first = u'您有一条新消息'
    data_obj.keyword1 = u'预计的测试'
    data_obj.keyword2 = time.strftime("%Y-%m-%d")
    data_obj.remark = u"点我查看详细内容"
    touser = 'o88KNt_guARLrUD9TeiFC3aOScw4'
    url = 'http://www.baidu.com'
    print dycg(touser,url,data_obj)